#ifndef _SCUDB_BLIST_H_
#define _SCUDB_BLIST_H_

#include "sd_global.h"

struct sd_Blist;
struct sd_MemoryAllocator;

typedef struct sd_BlistNode
{
	struct sd_Blist* blist;
	struct sd_BlistNode* next;
	size_t usedcount;
	size_t capacity;
	uint8  buf[1];
}sd_BlistNode;

typedef struct sd_Blist
{
	size_t elemsize;
	size_t totalcount;
	size_t node_cap;
	sd_BlistNode* firstNode;
	sd_BlistNode* lastNode;
	struct sd_MemoryAllocator* ma;
}sd_Blist;

typedef struct sd_BlistIterator
{
	sd_Blist* blist;
	sd_BlistNode* curnode;
	int curindexInNode;
}sd_BlistIterator;

sd_Ret sd_BlistCreate(sd_Blist* blist, size_t elemsize, size_t node_cap, struct sd_MemoryAllocator* ma);
sd_Ret sd_BlistFree(sd_Blist* blist);
sd_Ret sd_BlistPushback(sd_Blist* blist, const void* elem);
sd_Ret sd_BlistInsert(sd_Blist* blist, const void* elem);
sd_Ret sd_BlistInsertTogether(sd_Blist* blist, const void* elem1, size_t elem1size, const void* elem2);
sd_Ret sd_BlistBegin(sd_Blist* blist, sd_BlistIterator* iter);
sd_Ret sd_BlistNext(sd_BlistIterator* iter);
sd_Ret sd_BlistHasMore(sd_BlistIterator* iter);
sd_Ret sd_BlistGet(sd_BlistIterator* iter, void* elem);
sd_Ret sd_BlistPartialGet(sd_BlistIterator* iter, void* key, int offset, size_t size);
sd_Ret sd_BlistRemove(sd_BlistIterator* iter);
sd_Ret sd_BlistClear(sd_Blist* blist);
sd_Ret sd_BlistUpdate(sd_BlistIterator* iter, const void* elem);
sd_Ret sd_BlistUpdateTogether(sd_BlistIterator* iter, const void* elem1, size_t elem1size, const void* elem2);


#endif

